package cn.silver.framework.mybatis.domain;

import cn.hutool.core.util.IdUtil;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;

/**
 * Entity基类
 *
 * @author Silver Zhou
 */

@Data
@Schema(name = "BaseEntity", description = "基础实体")
public class BaseEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(title = "数据主键")
    @Id(keyType = KeyType.Auto)
    private String id;

    public void preInsert() {
        if (StringUtils.isBlank(this.id)) {
            this.id = IdUtil.getSnowflakeNextIdStr();
        }
    }

    public void preUpdate() {
    }
}
